package cn.schoolwow.flow.monitor.test.config;

import cn.schoolwow.flow.monitor.domain.handler.FlowMonitorFlowMappingHandler;
import cn.schoolwow.flow.monitor.domain.handler.FlowMonitorQuickFlowCommonTryCatchFinally;
import cn.schoolwow.quickflow.QuickFlow;
import cn.schoolwow.quickflow.QuickFlowBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@ComponentScan("cn.schoolwow.flow.monitor.test")
@Configuration
public class QuickFlowConfig {
    @Bean
    @Autowired
    public QuickFlow quickFlow(ApplicationContext applicationContext) {
        QuickFlow flowMonitorFlow = QuickFlowBuilder.newInstance()
                .putContextTemporaryInstanceData(applicationContext, ApplicationContext.class)
                .putContextTemporaryInstanceData(applicationContext.getEnvironment(), Environment.class)
                .tryCatchFinallyHandler(applicationContext.getBean(FlowMonitorQuickFlowCommonTryCatchFinally.class))
                .flowNameInstanceMappingHandler(applicationContext.getBean(FlowMonitorFlowMappingHandler.class));
        return flowMonitorFlow;
    }
}
